﻿Imports System.Data.SqlClient

Public Class frmJobOffers

    Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
        Dim a As New frmJobOfferNew
        a.Show()

    End Sub

    Private Sub frmJobOffers_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        loadGridOffers()
    End Sub

    Sub loadGridOffers()

        Try
            Me.Cursor = Cursors.WaitCursor
            Dim cmd As New SqlCommand
            cmd.CommandText = "Select SNo,EmpName,JobTitle,Branch,TotalSalary From JobOffers"

            cmd.Connection = cnn
            Dim reader As SqlDataReader
            cnn.Open()
            reader = cmd.ExecuteReader
            DataGridView1.Rows.Clear()
            While reader.Read
                Dim x As Integer = DataGridView1.Rows.Add
                With DataGridView1.Rows(x)
                    .Cells(DGColSNo.Name).Value = reader("SNo")
                    .Cells(DGVEmpName.Name).Value = reader("EmpName")
                    .Cells(DGVJobTitle.Name).Value = reader("JobTitle")
                    .Cells(DGVBranch.Name).Value = reader("Branch")
                    .Cells(DGVShow.Name).Value = "Show"
                End With
            End While
            cnn.Close()

            Me.Cursor = Cursors.Default
        Catch ex As Exception
            Me.Cursor = Cursors.Default
            If cnn.State = ConnectionState.Open Then
                cnn.Close()
            End If
            MsgBox(ex.ToString)
        End Try
    End Sub

    Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
        If e.ColumnIndex = -1 OrElse e.RowIndex = -1 Then Exit Sub
        If e.ColumnIndex = DGVShow.Index Then
            PrintJobOffer(DataGridView1.Rows(e.RowIndex).Cells(DGColSNo.Name).Value())
        End If
    End Sub
End Class